package com.jwell.IDcard.reader.api;

import com.sun.jna.Native;

/**
 * @author 唐旭
 * @version 1.0.0
 * @FileName:
 * @Company: 成都积微物联电子商务有限公司
 * @Date 2017/12/28
 * @remark:
 */
public abstract class ApiFactory {
    private static String WltRS_DLL_PATH = "WltRS";
    private static String STD_DLL_PATH = "sdtapi";
    private static String MSVCRT_DLL_PATH = "msvcrt";

    public static SdtApi getSdtApi() {
        String filePath = getPath(STD_DLL_PATH);
        return Native.loadLibrary(filePath, SdtApi.class);
    }

    private static String getPath(String path) {
        return ApiFactory.class.getResource("").getPath().replaceFirst("/", "")
                .replaceAll("/", "\\\\").replaceAll("%20", " ") + path;
    }

    public static PhotoDecoder getPhotoDecoder() {
        String filePath = getPath(WltRS_DLL_PATH);
        return Native.loadLibrary(filePath, PhotoDecoder.class);
    }

    @Deprecated
    public static Msvcrt getMsvcrt() {
        String filePath = ApiFactory.class.getResource("").getPath().replaceFirst("/", "").replaceAll("/", "\\\\").replaceAll("%20", " ") + MSVCRT_DLL_PATH;
        return Native.loadLibrary(filePath, Msvcrt.class);
    }
}
